<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title></title>
</head>
<body>
<style>
    .row-container {
        margin-top: 10px;
    }

    .row-container div:first-child {
        text-align: right;
        vertical-align: top;
        font-size: 15px;
        font-weight: bolder;
    }
</style>
<script>
    top.setMenuActionOpen("内容管理", "文章管理", "添加文章");
</script>
<form action="${pageContext.request.contextPath}/admin/article/save.html" method="post" onsubmit="return submitArticleForm(this)">
    <div class="row-container">
        <div style="display: inline-block;width: 200px;">文章标题：</div>
        <div style="display: inline-block;width: 300px;"><input type="text" name="title"
                                                                class="col-xs-12 "></div>
    </div>
    <div class="row-container">
        <div style="display: inline-block;width: 200px;">文章分类：</div>
        <div style="display: inline-block;width: 300px;">
            <select name="categoryId" class="form-control">
                <c:forEach items="${requestScope.data}" var="item">
                    <option value="${item.id}">${item.name}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="row-container">
        <div style="display: inline-block;width: 200px;">文章设置：</div>
        <div style="display: inline-block;width: 300px;">
            <label>
                <input name="isPublish" type="checkbox" class="ace">
                <span class="lbl">是否发布</span>
            </label> <label>
            <input name="isTop" type="checkbox" class="ace">
            <span class="lbl">是否置顶</span>
        </label>
        </div>
    </div>
    <div class="row-container">
        <div style="display: inline-block;width: 200px;">文章内容：</div>
        <div style="display: inline-block;width:900px;">
            <textarea name="content"></textarea>
        </div>
    </div>
    <div class="row-container">
        <div style="display: inline-block;width: 200px;">&nbsp;</div>
        <div style="display: inline-block;width:300px;">
            <button type="submit" class="btn btn-info"><i class="icon-ok"></i>提交</button>
            <button type="button" onclick="window.location.href='${pageContext.request.contextPath}/admin/article/manage.html'" class="btn btn-purple"><i class="icon-reply"></i>返回</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="${pageContext.request.contextPath}/assets/plugins/ckeditor/ckeditor.js"></script>
<script>
    var _editor=CKEDITOR.replace("content", {
        toolbarCanCollapse: false,
        resize_enabled: false,
        height: 500,
        toolbar: [
            ['Source','NewPage', 'Preview', 'Templates'],
            ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print', 'SpellChecker', 'Scayt'],
            ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript'],
            ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
            '/',
            ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
            ['Link', 'Unlink', 'Anchor'],
            ['Image','Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'],
            ['TextColor', 'BGColor'],
            '/',
            ['Styles', 'Format', 'Font', 'FontSize']

        ],
        filebrowserImageUploadUrl:'${pageContext.request.contextPath}/admin/article/imageUpload.html'
    });
    function submitArticleForm(d){
        var _form = $(d);
        var _title = _form.find("input[name=title]").val();
        if($.trim(_title).length<=0){
            Common.warning("请输入文章标题");
            return false;
        }
        if(_title.length>50){
            Common.warning("文章标题不能超过50个字");
            return false;
        }
        var _content = _editor.document.getBody().getHtml();
        if(_content.length<=0){
            Common.warning("请输入文章内容");
            return false;
        }
        return true;
    }
</script>
</body>
</html>
